package com.ywjh.inter.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedList;
import java.util.List;

import com.ywjh.inter.entity.DocGroupDiseaseEntity;

public class DocGroupDiseaseDAO {

	public List<DocGroupDiseaseEntity> list(Connection conn) throws SQLException {
		List<DocGroupDiseaseEntity> list = new LinkedList<DocGroupDiseaseEntity>();
		PreparedStatement ps = conn.prepareStatement("select * from doc_group_disease where status=1");
		ResultSet rs = ps.executeQuery();
		while (rs.next()) {
			DocGroupDiseaseEntity e = new DocGroupDiseaseEntity();
			e.setAdd_admin_id(rs.getInt("add_admin_id"));
			e.setAdd_time(rs.getTimestamp("add_time"));
			e.setId(rs.getInt("id"));
			e.setName(rs.getString("name"));
			e.setStatus(rs.getInt("status"));
			e.setDoc_group_id(rs.getInt("doc_group_id"));
			list.add(e);
		}
		return list;
	}
	
	public List<DocGroupDiseaseEntity> listByGroupId(Connection conn,int groupId) throws SQLException {
		List<DocGroupDiseaseEntity> list = new LinkedList<DocGroupDiseaseEntity>();
		PreparedStatement ps = conn.prepareStatement("select * from doc_group_disease where status=1 and doc_group_id=?");
		ps.setInt(1, groupId);
		ResultSet rs = ps.executeQuery();
		while (rs.next()) {
			DocGroupDiseaseEntity e = new DocGroupDiseaseEntity();
			e.setAdd_admin_id(rs.getInt("add_admin_id"));
			e.setAdd_time(rs.getTimestamp("add_time"));
			e.setId(rs.getInt("id"));
			e.setName(rs.getString("name"));
			e.setStatus(rs.getInt("status"));
			e.setDoc_group_id(rs.getInt("doc_group_id"));
			list.add(e);
		}
		return list;
	}

}
